﻿using System;
using System.Windows;
using PostProcGUI.Model;

namespace PostProcGUI.ModelView.ForModel
{
    public class LogViewModel : ViewModelBase
    {
        #region Поля

        private readonly Log _log = new Log();

        #endregion // Поля

        #region // Свойства

        public string Message
        {
            get { return _log.Message; }
            set
            {
                _log.Message = value;
                OnPropertyChanged("Message");
            }
        }

        public DateTime Time
        {
            get { return _log.Time; }
            set
            {
                _log.Time = value;
                OnPropertyChanged("Time");
            }
        }

        public Style Level
        {
            get
            {
                var res =  Application.LoadComponent(new Uri("View/Resource/TextStyles.xaml", UriKind.Relative)) as ResourceDictionary;
                if (res == null) return null;

                switch (_log.Level)
                {
                    case LogLevel.Normal:
                        return res["LogStyleNormal"] as Style;
                    case LogLevel.Critical:
                        return res["LogStyleCritical"] as Style;
                    default:
                        return res["LogStyleUnknow"] as Style;
                }
            }
        }

        #endregion // Свойства

        #region Конструкторы 

        public LogViewModel(string message, LogLevel level = LogLevel.Normal)
        {
            _log.Message = message;
            _log.Level = level;
            _log.Time = DateTime.Now;
        }

        #endregion // Конструкторы
    }
}
